﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using XCI.Extensions;
using XCI.Helper;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    public partial class FrmModifyPassword : BaseForm
    {
        public FrmModifyPassword()
        {
            InitializeComponent();
        }

        private async void btnSave_Click(object sender, EventArgs e)
        {
            string oldPwd = editOldPwd.Text;
            string newPwd = editNewPwd.Text;
            string confirmPwd = editComfirmPwd.Text;

            if (oldPwd.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入原密码");
                editOldPwd.Select();
                return;
            }

            if (newPwd.IsEmpty())
            {
                MessageBoxHelper.ShowWarn("请输入新密码");
                editNewPwd.Select();
                return;
            }

            if (!newPwd.Equals(confirmPwd))
            {
                MessageBoxHelper.ShowWarn("两次密码输入不一致请重新输入");
                editComfirmPwd.Select();
                return;
            }

            await SysAccountService.Instance.ModifyPasswordAsync(SysApp.CurrentUser.Id, oldPwd, newPwd);
            MessageBoxHelper.ShowMessage("密码修改成功");
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}